#include <stdio.h>
#include <stdlib.h>

int main()
{
	const int size = 80;

	// Read file
	FILE* file = fopen("matrix.txt","r");
	int** M = new int* [size];

	for (int i = 0; i < size; i++)
	{
		M[i] = new int [size];
		for (int j = 0; j < size; j++)
		{
			int n = 0;
			char c = fgetc(file);
			while (c >= '0' && c <= '9')
			{
				n *= 10;
				n += c - '0';
				c = fgetc(file);
			}
			M[i][j] = n;
		}
	}

	// go!
	for (int i = 1; i < size; i++)
		M[0][i] += M[0][i-1] ;

	for (int i = 1; i < size; i++)
		M[i][0] += M[i-1][0];

	for (int i = 1; i < size; i++)
		for (int j = 1; j < size; j++)
			M[i][j] = M[i-1][j] < M[i][j-1] ? M[i-1][j] + M[i][j] : M[i][j-1] + M[i][j];

	printf("%d", M[size-1][size-1]);

	return 0;
}
